package com.zwk.base.handler;

import com.zwk.base.entity.CommonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zwk
 * @create 2022/8/17 18:42
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResult error(Exception e){
        e.printStackTrace();
        return CommonResult.error().message("执行全局异常处理");
    }

    // 自定义异常
    @ExceptionHandler(GuLiException.class)
    @ResponseBody
    public CommonResult error(GuLiException e){
        e.printStackTrace();
        return CommonResult.error().message(e.getMsg()).code(e.getCode());
    }

}
